using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.Collections.ObjectModel;

namespace Microsoft.PowerShell.CmdletManagement
{
    public class ParameterSetSelector : IEquatable<ParameterSetSelector>
    {
        public ParameterSetSelector(bool isChecked, string parameterSetName)
        {
            this.isChecked = isChecked;
            this.ParameterSetName = parameterSetName;
        }

        public bool IsChecked
        {
            get { return isChecked; }
            set { isChecked = value; }
        }
        private bool isChecked;

        public string ParameterSetName
        {
            get { return parameterSetName; }
            set { parameterSetName = value; }
        }
        private string parameterSetName;

        #region IEquatable<ParameterSetSelector> Members

        public bool Equals(ParameterSetSelector other)
        {
            return this.ParameterSetName == other.ParameterSetName;
        }

        #endregion
    }

    public partial class PsSpecCmdletParametersControl : System.Windows.Controls.UserControl
    {
        public PsSpecCmdletParametersControl()
        {
            InitializeComponent();
        }

        private ObservableCollection<ParameterSetSelector> mergedParameterSets = new ObservableCollection<ParameterSetSelector>();

        public ObservableCollection<ParameterSetSelector> AllParameterSets
        {
            get 
            {
                List<PsSpecCmdletParameterDetails> parameters = (List<PsSpecCmdletParameterDetails>)this.DataContext;

                foreach (PsSpecCmdletParameterDetails parameterEntry in parameters)
                {
                    foreach (string parameterSetName in parameterEntry.ParameterSets)
                    {
                        ParameterSetSelector tempParameter = new ParameterSetSelector(false, parameterSetName);

                        if ((parameterSetName == null) || (parameterSetName.Trim().Length == 0))
                            continue;

                        if (!mergedParameterSets.Contains(tempParameter))
                        {
                            mergedParameterSets.Add(tempParameter);
                        }
                    }
                }

                ObservableCollection<ParameterSetSelector> returnSet = new ObservableCollection<ParameterSetSelector>();
                foreach (ParameterSetSelector item in mergedParameterSets)
                {
                    returnSet.Add(new ParameterSetSelector(false, item.ParameterSetName));
                }
                
                return returnSet;
            }
        }
    }
}